﻿using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using SyncWayBill.Service;
using Volo.Abp;

namespace SyncWayBill
{
    public class SyncWayBillHostedService : IHostedService
    {

        public Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create<SyncWayBillModule>(options =>
            {
                options.UseAutofac(); //Autofac integration
                options.Services.AddLogging(c => c.AddSerilog());
            }))
            {
                application.Initialize();
                //可以处理其他业务逻辑，这里测试数据库
                /*   var helloWorldService = application.ServiceProvider.GetService<HelloWorldService>();
                   helloWorldService.Test();*/

                // application.Shutdown();  定时执行不能关闭

                /* var test = application.ServiceProvider.GetService<SyncMadanStatus>();
                 test.Unloading();*/

                //var test = application.ServiceProvider.GetService<SendLoadService>();
                //test.SendWaybill();

                Log.Logger.Information("服务启动成功");
            }

            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
    }
}
